package com.dai.zhenfujin.visitingcard.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dai.zhenfujin.R;
import com.dai.zhenfujin.visitingcard.app.bean.LocationInfo;

import java.util.List;

public class LocationInfoAdapter extends BaseAdapter{

    private Context context;
    private List<LocationInfo> locationInfos;


    private LayoutInflater inflater;


    public LocationInfoAdapter(Context context, List<LocationInfo> locationInfos) {
        this.context = context;
        this.locationInfos = locationInfos;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return locationInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.locationinfo_lsitview,null);

            holder.tvName = (TextView)convertView.findViewById(R.id.locationinfo_lsitview_textview);
            convertView.setTag(holder);
        }else {

            holder = (ViewHolder) convertView.getTag();
        }
        LocationInfo info = locationInfos.get(position);
        holder.tvName.setText(info.getAddress());

        return convertView;
    }

    class ViewHolder{
       private TextView tvName;
    }

}
